extends layout
block content
  +header('create')
  .container
    form(style="width:100%" method="post" class="form create")
      div
        label 标题：
        input(placeholder="请输入标题" type="text" name="title")
      div
        label 内容：
        textarea(placeholder="请输入内容" name="content" id="" cols="42" rows="10")
      .submit 发表
append script
  script.
    $('.submit').click(function () {
      if ($('input[name=title]').val().trim() === '') {
        fade('请输入标题')
      } else if ($('textarea').val().trim() === '') {
        fade('请输入内容')
      } else {
        $.ajax({
          url: "/create",
          data: $('.form').serialize(),
          type: "POST",
          cache: false,
          dataType: 'json',
          success: function (msg) {
            console.log(msg)
            if (msg.code == 200) {
              fade('发表成功')
              setTimeout(function () {
                location.href = "/posts"
              }, 1000)
            } else {
              fade('发表失败')
            }
          },
          error: function () {
            alert('异常');
          }
        })
      }
    })